package rpc.proxy.jdk;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rpc.proxy.api.BaseProxyFactory;
import rpc.proxy.api.ProxyFactory;
import rpc.proxy.api.consumer.Consumer;
import rpc.proxy.api.object.ObjectProxy;
import rpc.spi.annotation.SPIClass;

import java.lang.reflect.Proxy;

/**
 * @version 1.0.0
 * @description JDK动态代理
 */
@SPIClass
public class JdkProxyFactory<T> extends BaseProxyFactory<T> implements ProxyFactory{
    private final Logger logger = LoggerFactory.getLogger(JdkProxyFactory.class);
        @Override
        public <T> T getProxy(Class<T> clazz) {
            logger.info("基于JDK动态代理");
            return (T) Proxy.newProxyInstance(
                    clazz.getClassLoader(),
                    new Class<?>[]{clazz},
                    objectProxy
            );
        }

}
